package com.kaifamiao.sync;

public class IcbcTest {

    public static void launch(String name, Runnable task) {
        Thread t = new Thread(task, name);
        t.start();
    }

    public static void main(String[] args) {

        final IcbcAccount account = new IcbcAccount("张无忌", 1000, 500 );

        // 用匿名内部类实现接口中的抽象方法
        Runnable depositTask = new Runnable() {
            @Override
            public void run() {
                for( int i = 0 ; i < 5 ; i++) {
                    account.deposit(800);
                    Thread.yield();
                }
            }
        };

        // 用 lambda 表达式 实现 函数式接口 中的抽象方法
        Runnable withdrawTask = () -> {
            for( int i = 0 ; i < 3 ; i++) {
                account.withdraw(800);
                Thread.yield();
            }
        };

        launch( "殷天正" , depositTask );
        launch( "曾阿牛", withdrawTask );
        launch( "殷离", withdrawTask );

    }

}
